package com.example.springDemo.service.impl;


import com.example.springDemo.bean.UserLong;
import com.example.springDemo.mapper.UserMapper;
import com.example.springDemo.service.UserLongService;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserLongServiceImpl implements UserLongService {

    @Autowired
    UserMapper userMapper;

    Counter counter;//次数
    public UserLongServiceImpl(MeterRegistry meterRegistry){
        counter = meterRegistry.counter("UserLongService.getUserById.count");
        //定制一个监控k 监控一个int次数

    }

    @Override
    public UserLong getUserById(Long id){
        counter.increment();//给他+1  表示调用了一次
        final UserLong userLong = userMapper.getUserLong(id);
        System.out.println(userLong);

        return userLong;
    }

    @Override
    public boolean setUserLong(UserLong userLong){

        return userMapper.insertUserLong(userLong);
    }
}
